
package com.kugou.game.sdk.ui.dialog;

import com.kugou.game.sdk.utils.Rx;

import android.app.Dialog;
import android.content.Context;
import android.text.Spanned;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;

/**
 * @Title: BaseCommonDialog.java
 * @Package com.kugou.pay.android.dialog
 * @Description: 对话框
 * @author 李德贤
 * @date 2013-4-25 下午5:41:48
 * @version V1.0
 */
public class BaseCommonDialog extends Dialog {

    protected Context mContext;

    protected ImageView mCanleTitle;

    protected TextView mTxtOne;

    protected TextView mTxtTwo;

    protected TextView mTxtThree;

    protected TextView mTxtFour;

    protected ScrollView mScrollView;

    protected LinearLayout mLinearLayout;

    protected Button mActivateAccount;

    protected Button mChangerAccount;

    protected Button mCanle;

    protected LinearLayout mLinearLayoutButton;

    protected TextView mTextTitle;

    public BaseCommonDialog(Context context) {

        this(context, 0);

    }

    public BaseCommonDialog(Context context, int theme) {
        super(context, theme);
        this.mContext = context;
        requestWindowFeature(Window.FEATURE_NO_TITLE);

    }

    @Override
    public void onContentChanged() {
        super.onContentChanged();
        mTextTitle = (TextView) findViewById(Rx.id.kg_common_dialog_title);
        if (mTextTitle == null) {
            throw new RuntimeException("Your content must have a ImageView whose id attribute is "
                    + "'R.id.kg_common_dialog_title'");
        }
        mCanleTitle = (ImageView) findViewById(Rx.id.kg_common_dialog_button);
        if (mCanleTitle == null) {
            throw new RuntimeException("Your content must have a ImageView whose id attribute is "
                    + "'R.id.kg_common_dialog_button'");
        }
        mCanleTitle.setOnClickListener(mCancelClickListener);
        mTxtOne = (TextView) findViewById(Rx.id.kg_get_activity_txt_one);
        if (mTxtOne == null) {
            throw new RuntimeException("Your content must have a TextView whose id attribute is "
                    + "'R.id.kg_get_activity_txt_one'");
        }
        mTxtTwo = (TextView) findViewById(Rx.id.kg_get_activity_txt_two);
        if (mTxtTwo == null) {
            throw new RuntimeException("Your content must have a TextView whose id attribute is "
                    + "'R.id.kg_get_activity_txt_two'");
        }
        mTxtThree = (TextView) findViewById(Rx.id.kg_get_activity_txt_three);
        if (mTxtThree == null) {
            throw new RuntimeException("Your content must have a TextView whose id attribute is "
                    + "'R.id.kg_get_activity_txt_three'");
        }

        mTxtFour = (TextView) findViewById(Rx.id.kg_get_activity_txt_four);
        // if (mTxtFour == null) {
        // throw new
        // RuntimeException("Your content must have a TextView whose id attribute is "
        // + "'R.id.kg_get_activity_txt_four'");
        // }
        mScrollView = (ScrollView) findViewById(Rx.id.kg_get_activity_txt_four_scrollview);
        // if (mScrollView == null) {
        // throw new
        // RuntimeException("Your content must have a TextView whose id attribute is "
        // + "'R.id.kg_get_activity_txt_four_scrollview'");
        // }
        mLinearLayout = (LinearLayout) findViewById(Rx.id.kg_user_center_linearlayout);
        if (mLinearLayout == null) {
            throw new RuntimeException("Your content must have a TextView whose id attribute is "
                    + "'R.id.kg_user_center_linearlayout'");
        }
        mActivateAccount = (Button) findViewById(Rx.id.kg_get_activate_account_button);
        if (mActivateAccount == null) {
            throw new RuntimeException("Your content must have a Button whose id attribute is "
                    + "'R.id.kg_get_activate_account_button'");
        }
        mChangerAccount = (Button) findViewById(Rx.id.kg_changer_account_button);
        if (mChangerAccount == null) {
            throw new RuntimeException("Your content must have a Button whose id attribute is "
                    + "'R.id.kg_changer_account_button'");
        }
        mCanle = (Button) findViewById(Rx.id.kg_canle_button);
        if (mCanle == null) {
            throw new RuntimeException("Your content must have a Button whose id attribute is "
                    + "'R.id.kg_canle_button'");
        }
        mCanle.setOnClickListener(mCancelClickListener);
        mLinearLayoutButton = (LinearLayout) findViewById(Rx.id.kg_user_center_button_all);
        if (mLinearLayoutButton == null) {
            throw new RuntimeException(
                    "Your content must have a LinearLayout whose id attribute is "
                            + "'R.id.kg_user_center_button_all'");
        }
    }

    private View.OnClickListener mCancelClickListener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    };

    public void setmActivateAccountClickListener(View.OnClickListener listener) {
        mActivateAccount.setOnClickListener(listener);
    }

    public void setmChangerAccountClickListener(View.OnClickListener listener) {
        mChangerAccount.setOnClickListener(listener);
    }

    public void setmCanleClickListener(View.OnClickListener listener) {
        mCanle.setOnClickListener(listener);
    }

    /**
     * 设置mTxtOne的文字
     */
    public void setmTxtOneText(String str) {
        mTxtOne.setText(str);
    }

    public void setmTxtOneTextSpanned(Spanned str) {
        mTxtOne.setText(str);
    }

    /**
     * 设置mTxtTwo的文字
     */
    public void setmTxtTwoText(String str) {
        mTxtTwo.setText(str);
    }

    /**
     * 设置mTxtThree的文字
     */
    public void setmTxtThreeText(String str) {
        mTxtThree.setText(str);
    }

    /**
     * 设置mTxtThree的文字
     */
    public void setmTxtFourText(String str) {
        if (mTxtFour == null) {
            return;
        }
        mTxtFour.setText(str);
    }

    /**
     * 设置mTextTitle的文字
     */
    public void setmTextTitleText(String str) {
        mTextTitle.setText(str);
    }

    /**
     * 设置mTxtOne隐藏
     */
    public void setHidemTxtOne(boolean boo) {
        if (boo) {
            mTxtOne.setVisibility(View.GONE);
        } else {
            mTxtOne.setVisibility(View.VISIBLE);
        }
    }

    /**
     * 设置mTxtTwo隐藏
     */
    public void setHidemTxtTwo(boolean boo) {
        if (boo) {
            mTxtTwo.setVisibility(View.GONE);
        } else {
            mTxtTwo.setVisibility(View.VISIBLE);
        }
    }

    /**
     * 设置mTxtThree隐藏
     */
    public void setHidemTxtThree(boolean boo) {
        if (boo) {
            mTxtThree.setVisibility(View.GONE);
        } else {
            mTxtThree.setVisibility(View.VISIBLE);
        }
    }

    /**
     * s 设置mTxtFour隐藏
     */
    public void setHidemScrollView(boolean boo) {
        if (mScrollView == null) {
            return;
        }
        if (boo) {
            mScrollView.setVisibility(View.GONE);
        } else {
            mScrollView.setVisibility(View.VISIBLE);
        }
    }

    public void setHidemActivateAccount(boolean boo) {
        if (boo) {
            mActivateAccount.setVisibility(View.GONE);
        } else {
            mActivateAccount.setVisibility(View.VISIBLE);
        }

    }

    public void setHidemChangerAccount(boolean boo) {
        if (boo) {
            mChangerAccount.setVisibility(View.GONE);
        } else {
            mChangerAccount.setVisibility(View.VISIBLE);
        }

    }

    public void setHidemCanle(boolean boo) {
        if (boo) {
            mCanle.setVisibility(View.GONE);
        } else {
            mCanle.setVisibility(View.VISIBLE);
        }
    }

    public void setHidemLinearLayout(boolean boo) {
        if (boo) {
            mLinearLayout.setVisibility(View.GONE);
        } else {
            mLinearLayout.setVisibility(View.VISIBLE);
        }
    }

    public void setHidemLinearLayoutButton(boolean boo) {
        if (boo) {
            mLinearLayoutButton.setVisibility(View.GONE);
        } else {
            mLinearLayoutButton.setVisibility(View.VISIBLE);
        }
    }

    public void setActivateAccountText(String txt) {
        mActivateAccount.setText(txt);
    }

    public void setChangerAccountText(String txt) {
        mChangerAccount.setText(txt);
    }

    public void setHidemChangerAccountText(String txt) {
        mCanle.setText(txt);
    }

    public void setActivateAccountTextColor(int color) {
        mActivateAccount.setTextColor(color);
    }

    public void setChangerAccountTextColor(int color) {
        mChangerAccount.setTextColor(color);
    }

    public void setHidemChangerAccountTextColor(int color) {
        mCanle.setTextColor(color);
    }

    public void setActivateAccountTextBGColor(int resid) {
        mActivateAccount.setBackgroundResource(resid);
    }

    public void setChangerAccountTextBGColor(int color) {
        mChangerAccount.setBackgroundResource(color);
    }

    public void setHidemChangerAccountTextBGColor(int color) {
        mCanle.setBackgroundColor(color);
    }

    public void setShowLinearLayout(View child) {
        mLinearLayout.addView(child);
    }

    public void setLinearLayout(View child) {
        mLinearLayout.addView(child);
    }

    public void setLinearLayout(View child, LayoutParams params) {
        mLinearLayout.addView(child, params);
    }

    public void setLinearLayout(View child, int width, int height) {
        mLinearLayout.addView(child, width, height);
    }

    public void setLinearLayout(View child, int index, LayoutParams params) {
        mLinearLayout.addView(child, index, params);
    }

    public void setLinearLayoutParams(int width, int height) {
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, height);
        mLinearLayout.setLayoutParams(params);
    }

    public void setScrollViewParams(int width, int height) {
        if (mScrollView == null) {
            return;
        }
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, height);
        mScrollView.setLayoutParams(params);
    }

    public void setLinearLayoutPadding(int left, int top, int right, int bottom) {
        mLinearLayout.setPadding(left, top, right, bottom);
    }
}
